package com.yequan.leeetcoden;

/**
 * @author yequan
 * @date 2021/06/13 15:15
 **/
public class ReserveLinkedList {

    public static void main(String[] args) {

    }

    public static ListNode reserve(ListNode head) {
        if (head == null || head.next == null) {
            return head;
        }
        ListNode preNode = null;
        ListNode currentNode = head;
        while (currentNode != null) {
            ListNode tempNode = currentNode.next;
            currentNode.next = preNode;
            preNode = currentNode;
            currentNode = tempNode;
        }
        return preNode;
    }

    public static ListNode reserve2(ListNode head) {
        if (null == head || head.next == null) {
            return head;
        }
        ListNode preNode = null;
        ListNode currentNode = head;
        while (currentNode != null) {
            ListNode tempNode = currentNode.next;
            currentNode.next = preNode;
            preNode = currentNode;
            currentNode = tempNode;
        }
        return preNode;
    }

    public static ListNode reserve3(ListNode head) {
        if (null == head || null == head.next) {
            return head;
        }
        ListNode preNode = null;
        ListNode currentNode = head;
        while (currentNode != null) {
            ListNode tempNode = currentNode.next;
            currentNode.next = preNode;
            preNode = currentNode;
            currentNode = tempNode;
        }
        return preNode;
    }

    public static ListNode reserve4(ListNode head) {
        if (null == head || null == head.next) {
            return head;
        }
        ListNode preNode = null;
        ListNode currentNode = head;
        while (currentNode != null) {
            ListNode tempNode = currentNode.next;
            currentNode.next = preNode;
            preNode = currentNode;
            currentNode = tempNode;
        }
        return preNode;
    }

}
